<template>
  <div id="activeCommentSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="人审结果" prop="manual">
          <el-select v-model="formInline.manual" clearable placeholder="请选择">
            <el-option
              v-for="(item, index) in resultsList"
              :key="index + item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="机审结果" prop="machine">
          <el-select
            v-model="formInline.machine"
            clearable
            placeholder="请选择"
          >
            <el-option
              v-for="(item, index) in machineList"
              :key="index + item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="排序" prop="sort">
          <el-select v-model="formInline.sort" placeholder="请选择">
            <el-option
              v-for="(item, index) in sortList"
              :key="index + item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="内容查询" prop="content">
          <el-input
            clearable
            v-model="formInline.content"
            placeholder="请输入文字内容查询"
          ></el-input>
        </el-form-item>
        <el-form-item label="用户搜索" prop="dpAccount">
          <el-input
            clearable
            v-model="formInline.dpAccount"
            placeholder="请输入用户大鹏号进行搜索"
          ></el-input>
        </el-form-item>
        <el-form-item label="帖子类型" prop="postType">
          <el-select
            v-model="formInline.postType"
            clearable
            placeholder="请选择"
          >
            <el-option
              v-for="(item, index) in postList"
              :key="index + item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="timeType">
          <el-select v-model="formInline.timeType" placeholder="">
            <el-option
              v-for="(item, index) in timeTypeList"
              :key="index + item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="-"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="审核人" prop="checkUserId">
          <el-select
            clearable
            v-model="formInline.checkUserId"
            placeholder="请选择"
            filterable
          >
            <el-option
              v-for="(item, index) in personList"
              :key="index + item.dapengUserId"
              :label="item.nickname"
              :value="item.dapengUserId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户属性" prop="userProperty">
          <el-select v-model="formInline.userProperty" clearable>
            <el-option
              v-for="item in userAttList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button type="success" icon="el-icon-search" @click="toSearch()">
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { getCreateTime } from '@utils/pubFunction'
import { getDpNum } from '@/api/system/user'

export default {
  name: 'ActiveCommentSearch',
  msg: '活动帖子评论审核-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          manual: 0,
          machine: 0,
          sort: 1,
          content: '',
          timeType: 0,
          postType: 0,
          checkUserId: 0,
          dpAccount: '',
          userProperty: '', // 用户属性
          startTime: '',
          endTime: '',
          createTime: []
        }
      }
    }
  },
  data() {
    return {
      // 人审结果
      resultsList: [{ dictLabel: '全部', dictValue: '' }],
      // 机审结果
      machineList: [{ dictLabel: '全部', dictValue: '' }],
      // 排序
      sortList: [],
      // 排序2
      timeTypeList: [],
      // 帖子类型
      postList: [{ dictLabel: '全部', dictValue: '' }],
      // 审核人
      personList: [{ nickname: '全部', dapengUserId: '' }],
      userAttList: [{ dictLabel: '全部', dictValue: '' }], // 用户属性
      createTime: [] //  创建时间
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  },
  mounted() {
    this.getTopSearch()
    this.getCheckUser()
  },
  methods: {
    // 获取顶部搜索条件
    async getTopSearch() {
      let examineList = await sysNormalDisable('sys_audit_status', 'result')
      this.resultsList = this.resultsList.concat(examineList)
      this.machineList = this.machineList.concat(examineList)
      this.sortList = await sysNormalDisable('sys_audit_time_type')
      this.timeTypeList = await sysNormalDisable('sys_audit_search_type')
      let postList = await sysNormalDisable('sys_posts_type')
      this.postList = this.postList.concat(postList)
      // 用户属性
      let UserAttr = await sysNormalDisable(
        'comment_user_attributes',
        'checkUserAttr'
      )
      this.userAttList = this.userAttList.concat(UserAttr)
      this.setDefaultValue()
      //触发列表获取权限
      this.$emit('toSearch')
    },
    /*设置默认数据*/
    setDefaultValue() {
      this.formInline.sort = this.sortList[0].dictValue
      this.formInline.timeType = this.timeTypeList[0].dictValue
    },
    getCheckUser() {
      getDpNum({ type: 'OPERATORS' }, (response) => {
        this.personList = this.personList.concat(response)
      })
    },
    /* 搜索 */
    toSearch() {
      this.$emit('toSearch')
    },
    /* 重置 */
    reset() {
      this.$refs.ruleForm.resetFields()
      this.getCreateTime()
      //设置默认数据
      this.setDefaultValue()
    },
    getCreateTime() {
      const createTime = getCreateTime()
      this.formInline.createTime = createTime
    }
  }
}
</script>

<style lang="less">
#activeCommentSearch {
  .el-input {
    &.el-input--suffix {
      width: 182px !important;
    }
  }
}
</style>
